home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 107_01.zip / TESTCLOG.C < prev    next >
Text File  |  1993-06-06  |  8KB  |  299 lines

  1.  
  2.  
  3.  /* TESTCLOG.C ****** testing program for
  4.     CLOGS.C testing pi, expe, exp10, and log10   functions
  5.     calls for entry of a number, multiplies it by pi,
  6.     obtains log10 of number and of pi times
  7.     obtains exp10 of two logs
  8.     obtains exp10 and expe of number and pi product
  9.   */
  10.  
  11.  main()
  12. {
  13.     char rlog[5], rlogpi[5], xin[5], x[5];
  14.     char rpi[5], rexp10[5], rexp10pi[5];
  15.     char rexpe[5], rexpepi[5], rexlog[5];
  16.     char rexlogpi[5];
  17.     char *log10(), *expe(), *pi(), *exp10();
  18.     char stringin[80], pival[5];
  19.      int *sign1, *sign2;
  20.  
  21. while(1)
  22.     {printf("\n Enter input value ");
  23.      gets(stringin);
  24.      atof(xin,stringin);
  25.      fpasg(x,xin);
  26.      pi(pival);
  27.      fpmult(rpi,pival,xin);
  28.      printf("\n Input %e pi %e times pi %e",x,pival,rpi);
  29.      expe(rexpe,x);
  30.      expe(rexpepi,rpi);
  31.      printf("\n expe %e expe of pi times %e",rexpe,rexpepi);
  32.      fpasg(x,xin);
  33.      exp10(rexp10,x);
  34.      exp10(rexp10pi,rpi);
  35.      printf("\n exp10 %e exp10 of pi times %e",rexp10,rexp10pi);
  36.      fpasg(x,xin);
  37.      log10(rlog,sign1,x);
  38.      log10(rlogpi,sign2,rpi);
  39.      printf("\n log10 %f sign %d log10 of pi %f sign %d",
  40.         rlog,*sign1,rlogpi,*sign2);
  41.      fpasg(x,xin);
  42.      exp10(rexlog,rlog);
  43.      exp10(rexlogpi,rlogpi);
  44.      if(*sign1 < 0) fpchs(rexlog,rexlog);
  45.      if(*sign2 < 0) fpchs(rexlogpi,rexlogpi);
  46.      printf("\n In %e PIVAL %e unlog %e unlogpi %e \n",
  47.         x, rpi, rexlog, rexlogpi);
  48.     }
  49. }
  50. ;
  51. {
  52.     char *zero, *one, *large, *coef[7], *eghty6, *meghty6;
  53.     char intres[5], xint[5], x[5];
  54.     char  *fpmult(), *fpasg(), *fpd
  55.  
  56.  
  57.  
  58.  
  59.  
  60.                       NOTES ON "LOG" FUNCTIONS FOR BDS - C
  61.  
  62.  
  63.                                   Introduction
  64.  
  65.  
  66.       These "log" functions were developed so that I could do some auxiliary
  67.  
  68. work on scaling and curve generation for a graphics package I'm now doing in
  69.  
  70. BDS-C.  They seem to work OK in my setup which is now:  
  71.  
  72.        o  Altair 8800b, 64K CPM 2.2 BDS-C vers 1.44 
  73.  
  74.        o  Tarbell SSSD 4 8 inch disk 
  75.  
  76.        o  Scion Microangelo 
  77.  
  78.        o  LSI ADM3A 
  79.  
  80. This package was developed by:  
  81.  
  82. L. C. Calhoun PE 
  83.  
  84. 257 South Broadway 
  85.  
  86. Lebanon, Ohio 45036 
  87.  
  88. <513> 932-4541/433-7510 
  89.  
  90.                        SPECIAL NOTE ON VERSION OF BDS - C
  91.  
  92.  
  93.       The CLOGS programs have been written to take advantage of the ability to
  94.  
  95. insert '\0' into string constants which make it possible to use string constant
  96.  
  97. as pseudo-static floating point constants.  
  98.  
  99.  
  100.  
  101.       These programs are written in BDS-C using the floating point package
  102.  
  103. modified to add truncation and magnitude functions.  This package is called
  104.  
  105. "FLOAT+44".  The following functions are mechanized:  
  106.  
  107.      char *expe(result,x) 
  108.  
  109.      char *result, *x;   /* usual [5] char arrays for fp */ 
  110.  
  111.           The program returns the base of natural logs "e" raised to the power
  112.  
  113.           given in x.  The program is limited to work within the bounds of the
  114.  
  115.  
  116.  
  117.  
  118.  
  119.                                         1
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.           floating point variable.  The function returns the pointer to the
  130.  
  131.           result.  Values outside floating point bounds for the result are set
  132.  
  133.           to either zero or a very large number on the order of 2e38.  No error
  134.  
  135.           flags exist or are set.  
  136.  
  137.      char *exp10(result,x) 
  138.  
  139.      char *result, *x;   /* as with expe */ 
  140.  
  141.           Identical to expe, except the base of briggs logs "10" is raised to
  142.  
  143.           the power indicated by x.  
  144.  
  145.      char *log10(result,sign,x) 
  146.  
  147.      char *result, *x;    /*as with expe */ 
  148.  
  149.      int *sign; 
  150.  
  151.      char *angle, *datum;    
  152.  
  153.           This returns the logarithm to the base 10 in result of the value in x.
  154.  
  155.           x is unchanged.  Logarithms are computed of the magnitude of x, and
  156.  
  157.           negative x values return a -1 in sign.  Positive x values produce a 1
  158.  
  159.           in sign.  Very large or small values are returned for out   of range
  160.  
  161.           data.  There is no over/underflow indication.  Also returns pointer to
  162.  
  163.           result.  
  164.  
  165.                                      Method
  166.  
  167.  
  168.       The methods used are outlined in "Functional Approximations" by Fred
  169.  
  170. Ruckdeschel; page 34 ff in BYTE for November 1978.  Note the corrections in the
  171.  
  172. January 1979 issue.  A number of references are given in that article, and are
  173.  
  174. recommended reading.  There is an error in Ruckdeschel' article, in Table 3b.
  175.  
  176. The term to the right of the equals should all be enclosed in brackets and
  177.  
  178. squared.  Refer to equation 4.2.47 in Ruckdeshel' reference 6.  The following
  179.  
  180. service function is used:  
  181.  
  182.      int exprange(x) 
  183.  
  184.  
  185.  
  186.  
  187.  
  188.                                         2
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.      char *x; 
  199.  
  200.           This is used in the series evaluations.  Input is a pointer to the
  201.  
  202.           BDS-C type floating point variable.  It returns a 1 (true) if -47 <=
  203.  
  204.           exponent <= 47.  Outside of the range of exponent a 0 (false) is
  205.  
  206.           returned.  The exponent is a power of 2, so the effective range is
  207.  
  208.           about 1.4e14 to 7.e-15 for exponent in decimals.  The function is used
  209.  
  210.           to avoid a series computation overflowing the exponent which wraps a
  211.  
  212.           small exponent into a large one and vice-versa.  
  213.  
  214.  
  215.  
  216.       A number of checks are made for very large and very small data, to protect
  217.  
  218. the evaluation from the underflow and overflow failures of the floating point
  219.  
  220. package.  I have used TESTCLOG to evaluate over a wide range of variables, and I
  221.  
  222. think! I got all the gotchas.  It looks as though the package has (except at
  223.  
  224. infinity) about an absolute accuracy of .00001.  You will note that I use the
  225.  
  226. properties of the floating point numbers to do magnitude and sign checks.  Lots
  227.  
  228. faster than using fpcomp().  There is another program included, COEFSTAT, which
  229.  
  230. I used to derive the five octal equivalents for the pseudo-static terms in the
  231.  
  232. series evaluations, etc.  This will only work with BDS C V 1.44 (and later, I
  233.  
  234. hope) which allows insertion of nulls ('\0') in string constants.  The string
  235.  
  236. constants are used as pseudo-static floating point constants..and work very
  237.  
  238. well.  
  239.  
  240.  
  241.  
  242.                         Components of the CLOGS Package
  243.        1. CLOGS.DOC             This documentation file 
  244.  
  245.        2. CLOGS.C               Source for trig package 
  246.  
  247.        3. COEFSTAT.C            Source for coeficient determing program 
  248.  
  249.        4. TESTCLOG.C            Source for trig function testing program 
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.                                         3
  258.  
  259.  
  260.  
  261. power);
  262.     fpsub(x,x,tenfac);
  263.     fpasg(tenfac,one);
  264.     while (tenpower)
  265.         Software contributions are received for inclusion into the
  266.   library with the understanding that the contributor is
  267.   authorized to make the material available to others for their
  268.   individual, non-commercial use.  The Users Group makes no
  269.   representations as to the utility of the material in the
  270.   library for any purpose.  Contributions should be submitted
  271.   on 8" single density diskettes in CP/M file form.  Please
  272.   cross reference any rewrites or bug-fixes to prior
  273.   distributions
  274.  
  275. National CP/M Users Group - Program Submission Form
  276.  
  277. Submission Date: 27 July 1981 
  278.  
  279. Files names:    FLOAT+44.*  Files pertaining to a modified
  280.                 floating point package for
  281.                 BDS-C.  These files upgrade
  282.                 my previous FLOATXT.*
  283.                 submission.  Files are
  284.         FLOAT+44.C  Source, includes fixed "z" in _spr
  285.         FLOAT+44.CRL compiled version with V 1.44
  286.         FLOAT+44.DOC Documentation from FLOAT.DOC, updated
  287.         NEWFLVAL.C   Source of test program for float pkg
  288.         NEWFLVAL.CRL compiled version with V 1.44 & FLOAT+44
  289.         NEWFLVAL.COM linked version with FLOAT+44 for test
  290.  
  291.         COEFSTAT.C   Source of program to derive octal string
  292.                 equivalent of fp constants
  293.         COEFSTAT.CRL compiled version with V 1.44
  294.  
  295.         CTRIG.C      Source of updated trignometric functions
  296.                 working with BDS-C V 1.44 and FLOAT+44
  297.                 Update of CTRIG previously submitted
  298.                 to BDS-C UG.
  299.         CTRIG.CRL    compiled vers